package com.zhihuichongcheng.application.ui.cricle.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartlib.cmnObject.dialog.DialogOnClick;
import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.bean.cricle.CricleTypeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 3water on 2016/10/31.
 */

public class CricleTypeAdapter extends RecyclerView.Adapter<CricleTypeAdapter.ViewHold> {
    private Context mContext;

    private DialogOnClick<CricleTypeBean> onClickListener;
    private List<CricleTypeBean> mList = new ArrayList<>();
    public CricleTypeAdapter(Context context)
    {
        this.mContext = context;
    }
    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_cricle_type,null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, final int position) {
       final  CricleTypeBean bean = mList.get(position);
        holder.mTvName.setText(bean.getCategoryName());
        List<CricleTypeBean> list = bean.getSubCategories();
        if(list!=null&&list.size()>0)
        {
            holder.mImArrow.setVisibility(View.VISIBLE);
        }
        else
        {
            holder.mImArrow.setVisibility(View.GONE);
        }
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener!=null)
                {
                    onClickListener.onClick(bean);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void setData(List<CricleTypeBean> list) {
        this.mList = list;
    }

    public void setOnClickListener(DialogOnClick<CricleTypeBean> onClick) {
        this.onClickListener = onClick;
    }

    class ViewHold extends RecyclerView.ViewHolder{
        private TextView mTvName;
        private ImageView mImArrow;
        private View view;
        public ViewHold(View itemView) {
            super(itemView);
            view = itemView;
            mTvName = (TextView)itemView.findViewById(R.id.tv_name);
            mImArrow = (ImageView)itemView.findViewById(R.id.im_arrow);
        }
    }

}
